package org.orion.engine;

import javax.media.opengl.GL;

public class Program {
	private int id;
	
	public Program(){
		this.id = GLStatic.gl.glCreateProgram();
	}
	
	public Program(String vertex, String fragment){
		this.id = GLStatic.gl.glCreateProgram();
		Shader vertexShader = new Shader(GL.GL_VERTEX_SHADER);
		vertexShader.load(vertex);
		vertexShader.glSource();
		vertexShader.glCompile();

		Shader fragmentShader = new Shader(GL.GL_FRAGMENT_SHADER);
		fragmentShader.load(fragment);
		fragmentShader.glSource();
		fragmentShader.glCompile();
		
		glAttach(vertexShader);
		glAttach(fragmentShader);
	}
	
	public void glAttach(Shader shader){
		GLStatic.gl.glAttachShader(id, shader.getId());
	}
	
	public void glLink(){
		GLStatic.gl.glLinkProgram(id);
	}
	
	public void glUse() {
		GLStatic.gl.glUseProgram(id);
	}
	
	public static void glUnUse() {
		GLStatic.gl.glUseProgram(0);
	}

	public int getId() {
		return id;
	}
}
